package cn.gameo2o.controller.yhgl;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import cn.gameo2o.pojo.O2o_users;
import cn.gameo2o.service.yhgl.YongHuGuanLiService;
import cn.gameo2o.util.PageParam;
/*
 * 用户管理
 * @author 王振勇
 *
 */
@RestController
@RequestMapping("/yhgl")
public class YongHuGuanLiController {
	 @Resource()
	    private YongHuGuanLiService yhglService;

	    public YongHuGuanLiService getStudentService() {
	        return yhglService;
	    }

	    public void setStudentService(YongHuGuanLiService  YongHuService) {
	        this.yhglService =  YongHuService;
	    }
	    @RequestMapping("/find")
	    public PageParam findAll(@RequestParam(required = false) String username,@RequestParam(required = false) Date createdate,@RequestParam() Integer limit,@RequestParam() Integer offset){
	          Map param=new HashMap();
	          if(username!=null) {
	              param.put("username", username);
	          }
	          if(createdate!=null){
	              param.put("createdate",createdate);
	          }
	          PageParam page=new PageParam();
	          page.setPageSize(limit);
	          page.setFirst(offset);
	          yhglService.find(param,page);
	          return page;
	    }
	    @RequestMapping("/save")
	    public String save(@ModelAttribute O2o_users user){
	    	yhglService.save(user);
	        return "index";
	    }
	    @RequestMapping("/delete")
	    public String delete(@RequestParam(value = "sid",required = false) String id){
	    	yhglService.delete(Integer.parseInt(id));
	        return "删除成功！";
	    }

	    @RequestMapping("/findById")
	    public O2o_users  findById(@RequestParam(value="sid",required=false) String id ){
	    	O2o_users   users = yhglService.findById(Integer.parseInt(id));
	        return users;
	    }

	    @RequestMapping("/update")
	    public String update(@ModelAttribute O2o_users user){
	        yhglService.update(user);
	        return "更新成功！";
	    }
	}
